package idv.arthur.deployer;

import java.io.IOException;

import org.jboss.as.cli.CommandContext;
import org.jboss.as.cli.CommandLineException;
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.dmr.ModelNode;

public class DepCtx {

	final static String USER = "jboss";
	final static String PASSWORD = "jboss1234!@#$";
	final static String IPADDR = "10.144.97.99";
	final static int MGTPORT = 9949;

	public static void main(String[] args) throws IOException {
		CommandContext ctx = null;
		ModelControllerClient client = null;
		try {

			ctx = org.jboss.as.cli.CommandContextFactory.getInstance()
					.newCommandContext(USER, PASSWORD.toCharArray());

			ctx.connectController(IPADDR, MGTPORT);
			client = ctx.getModelControllerClient();
			String commandLine = ":read-resource()";
			ModelNode requestNode = ctx.buildRequest(commandLine);
			ModelNode result = client.execute(requestNode);
			String res = result.get("result").get("deployment").toString();
			System.out.println(res);
			
		} catch (CommandLineException e) {
			e.printStackTrace();
		} finally {
			if( client!=null ) { client.close(); }
			if( ctx!=null ) { ctx.disconnectController(); };
		}

	}

}
